package com.msos.service.BQueryService;

import com.msos.dao.BQueryDao.BQueryDao;
import com.msos.model.business.Business;
import com.msos.model.customer.Customer;
import com.msos.model.customer.Customer_Business;
import com.msos.utils.CommonsUtils;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @ClassName: BQueryService
 * @Description: TODO
 * @Author: hsx
 * @Date: 2022/4/14 9:16
 * @Version: v1.0
 */
public class BQueryService {
    BQueryDao bQueryDao = new BQueryDao();

    public List<Business> getAllBusiness(Customer customer) {
        try {
            List<Customer_Business> list = bQueryDao.getBusinessId(customer.getUid());
            List<Business> list1 = new ArrayList<>();
            for (int i = 0; i < list.size(); i++) {
                Business business = bQueryDao.getBusiness(list.get(i).getBid());
                list1.add(business);
            }
            return list1;
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }

    public Integer deleteBusiness(String bid) {
        try {
            return bQueryDao.deleteBusiness(bid);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return CommonsUtils.EXCEPTION_ERROR;
    }

    public List<Business> getAllBusinesses(Customer customer) {
        try {
            List<Customer_Business> list = bQueryDao.getBusinessId(customer.getUid());
            return bQueryDao.getAllBusinesses(list);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }

    public Integer addBusiness(String bid, Customer customer) {
        try {
            return bQueryDao.addBusiness(bid,customer.getUid());
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return CommonsUtils.EXCEPTION_ERROR;
    }
}